define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {

    var Controller = {
        detail: function () {
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        addvisitor: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                $("#c-category2").data("params", function (obj) {
                    return {custom: {pid: $("#c-category1").val()}};
                });
                $("#c-category3").data("params", function (obj) {
                    return {custom: {pid: $("#c-category2").val()}};
                });
                $("#c-category4").data("params", function (obj) {
                    return {custom: {pid: $("#c-category3").val()}};
                });
                $(document).on("change", "#c-category1", function () {
                    require(['selectpage'], function () {
                        $('#c-category2').selectPageClear();
                        $('#c-category3').selectPageClear();
                        $('#c-category4').selectPageClear();
                        $("#c-area_ids").val($('#c-category1').val());
                    });
                });
                $(document).on("change", "#c-category2", function () {
                    require(['selectpage'], function () {
                        $('#c-category3').selectPageClear();
                        $('#c-category4').selectPageClear();
                        $("#c-area_ids").val( $("#c-category1").val()+","+$("#c-category2").val());
                    });
                });
                $(document).on("change", "#c-category3", function () {
                    require(['selectpage'], function () {
                        $('#c-category4').selectPageClear();
                        $("#c-area_ids").val( $("#c-category1").val()+","+$("#c-category2").val()+","+$("#c-category3").val());
                    });
                });
                $(document).on("change", "#c-category4", function () {
                    $("#c-area_ids").val( $("#c-category1").val()+","+$("#c-category2").val()+","+$("#c-category3").val()+","+$("#c-category4").val());
                });
            }
        }
    };
    return Controller;

});